<?php
function getAccessToken()
{
 $data = json_decode(file_get_contents("access_token.json"));
    if ($data->expire_time < time()) {
      $url_get='https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx934cb7f852f6c585&secret=94ea78cbbbd72c8a0ecbfc965a497afc';
	  $json=json_decode(curlGet($url_get),true);
	if (!isset($json['errmsg']))
	{
			$access_token = $json['access_token'];
	      if ($access_token) {
	        $data->expire_time = time() + 7000;
	        $data->access_token = $access_token;
	        $fp = fopen("access_token.json", "w");
	        fwrite($fp, json_encode($data));
	        fclose($fp);
	      }
	}
	else {
		echo '获取access_token发生错误：错误代码,微信返回错误信息：';
	}
    } else {
      $access_token = $data->access_token;
    }
	
	return $access_token;
}

function curlGet($url,$data=null)
{
	 $curl = curl_init();
         curl_setopt($curl, CURLOPT_URL, $url);
         curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
         curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
         if (!empty($data)){
             curl_setopt($curl, CURLOPT_POST, 1);
             curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
         }
         curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
         $output = curl_exec($curl);
         curl_close($curl);
         return $output;
}
$data = json_encode(array("type"=>"news","offset"=>0,"count"=>2));
$access_token=getAccessToken();	//echo $access_token;exit;
$subscribe_msg = "https://api.weixin.qq.com/cgi-bin/material/batchget_material?access_token=".$access_token;
$subscribe = json_decode(curlGet($subscribe_msg,$data),true);
$record = array();
foreach ($subscribe['item'] as $s)
{
	foreach($s['content']['news_item'] as $scn){
		unset($scn['content']);
		unset($scn['content_source_url']);
		unset($scn['show_cover_pic']);
		unset($scn['thumb_media_id']);
		unset($scn['digest']);
		unset($scn['author']);
		$record[] = $scn;
	}
}
$result = array();
foreach ($record as $r)
{
	unset($scn['content']);
	$result[] = $r;
	$result[] = $r;
}
print_r($record);
exit;
?>